clc
clear
f = 262;%C调声音频率
Fs = 8000;%采样频率
T = 0:1/Fs:1.5-1/Fs;%声音持续1.5秒
Amp = [1 0 1/3 0 1/5 0 1/7 0 1/9 0]/pi;%高阶和弦振幅
Ph = (pi/2)*ones(1,10);%高阶和弦相位

sound_1 = sin(2*pi*f*T );%C调声音
sound_2 = sin(2*pi*f*T);
sum_harmon = zeros(1,length(T));%和弦声音之和
sum_rand_harmon = zeros(1,length(T));%随机和弦
for K = 1:10
    sound_harmon = Amp(K)*sin(2*pi*f*K*T+ Ph(K));%K阶和弦
    sound_rand_harmon = Amp(K)*sin(2*pi*f*K*T+(2*rand()-1)*pi);%随机相位和弦
    sum_harmon = sum_harmon + sound_harmon;
    sum_rand_harmon = sum_rand_harmon + sound_rand_harmon;
end
sound_1 = sound_1 + sum_harmon;%信号1
sound_2 = sound_2 + sum_rand_harmon;%信号2

choice_1 = floor(rand()*2);%选择信号
if(choice_1 == 1)
    sound(sound_1,Fs);
else
    sound(sound_2,Fs);
end
disp('next')
pause(1)%暂停1秒
choice_2 = floor(rand()*2);
if(choice_2 == 1)
    sound(sound_1,Fs);
else
    sound(sound_2,Fs);
end
disp('两者是否一致?')
%disp('y:一致')
%disp('n:不一致')
%x = input('请输入y/n');
if(choice_1 == choice_2)
    %a = 'y'
    disp('一致')
else
    %a = 'n'
    disp('不一致')
end
%if(x == a)
%    disp('对了')
%else
%    disp('错了')
%end